﻿/** Pete's Tools package */
package pete.tools
{
	import flash.display.DisplayObjectContainer;
	
	/**
	 * @version
	 * 0.1
	 *
	 * @description 
	 * Removes all the children of a target DisplayObjectContainer except for the give <code>...args</code>.
	 * 
	 * @example
	 * <pre>
	 * var holder:Sprite = new Sprite ();
	 * var test1:Sprite = new Sprite ();
	 * var test2:Sprite = new Sprite ();
	 * var test3:Sprite = new Sprite ();
	 * <br />
	 * holder.addChild (test1);
	 * holder.addChild (test2);
	 * holder.addChild (test3);
	 * <br />
	 * removeChildren (holder, test1, test2); // only test1, test2 are children.
	 * removeChildren (holder); // no children left.
	 * </pre>
	 *
	 * @param target Target DisplayObjectContainer to remove the children from.
	 * @param ...args Children ignored by this command.
	 */
	public function removeChildren (target:DisplayObjectContainer, ...args):void
	{
		while (target.numChildren > 0)
		{
			target.removeChildAt (0);
		}
		
		for each (var arg in args)
		{
			target.addChild (arg);
		}
	}
}